package com.aiyige.model.response;

import android.text.TextUtils;

import com.aiyige.MyApp;
import com.aiyige.R;

/**
 * Created by xiachao on 2018/1/22.
 */

public class ErrorResponse {

    private ErrorResponse(Builder builder) {
        setCode(builder.code);
        setMessage(builder.message);
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return TextUtils.isEmpty(message) ? (MyApp.getAppContext().getString(R.string.service_error,code)) : message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    String code;
    String message;

    public ErrorResponse() {
    }

    public ErrorResponse(ErrorResponse other) {
        this.code = TextUtils.isEmpty(other.code) ? "" : other.code;
        this.message = TextUtils.isEmpty(other.message) ? "" : other.message;
    }

    public static final class Builder {
        private String code;
        private String message;

        private Builder() {
            code = "";
            message = "";
        }

        public Builder code(String code) {
            this.code = code;
            return this;
        }

        public Builder message(String message) {
            this.message = message;
            return this;
        }

        public ErrorResponse build() {
            return new ErrorResponse(this);
        }
    }
}
